package com.liull.netty.cust_protocol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @Author: liull
 * @Description: 自定义编码器，将消息，转换为bytebuffer
 * @Date: Created in 16:54 2020/11/15
 * @Modified By:
 */
public class PersonEncoder extends MessageToByteEncoder<PersonProtocol> {

    @Override
    protected void encode(ChannelHandlerContext ctx, PersonProtocol msg, ByteBuf out) throws Exception {
        System.out.println("PersonEncoder encode invoked!");
        out.writeInt(msg.getLength());
        out.writeBytes(msg.getContent());
    }
}
